package edu.bbu.license.client.android.services;

import edu.bbu.license.client.android.utility.PersistenceProvider;

public abstract class BaseService {

	public static final String SYNC_DIR = "SYNC_DIR";
	public static final String SYNC_TYPE = "SYNC_TYPE";
	public static final String SYNC_ENABLED = "SYNC_ENABLED";
	public static final String SYNC_ONE_WAY = "SYNC_ONE_WAY";
	public static final String SYNC_TWO_WAY = "SYNC_TWO_WAY";
	
	
	public static final String LOGGED_IN_USER = "LOGGED_IN_USER";
	
	private static final PersistenceProvider persistanceProvider = new PersistenceProvider();
	
	public synchronized void setCurrentlyLoggedInUser(String currentUser) {
		persistanceProvider.saveValue(LOGGED_IN_USER, currentUser);
	}

	public synchronized String getCurrentlyLoggedInUser() {
		return persistanceProvider.getValue(LOGGED_IN_USER);
	}

	public synchronized void removeCurrentlyLoggedInUser() {
		persistanceProvider.removeValue(LOGGED_IN_USER);
	}

	public synchronized boolean isUserLoggedIn() {
		return !persistanceProvider.getValue(LOGGED_IN_USER).isEmpty();
	}
	
	public synchronized void setAutoSyncEnabled(boolean enabled) {
		persistanceProvider.saveValue(SYNC_ENABLED, Boolean.toString(enabled));
	}
	
	public synchronized boolean isAutoSyncEnabled() {
		return Boolean.parseBoolean(persistanceProvider.getValue(SYNC_ENABLED));
	}
	
	public synchronized void setOneWaySyncType() {
		persistanceProvider.saveValue(SYNC_TYPE, SYNC_ONE_WAY);
	}
	
	public synchronized void setTwoWaySyncType() {
		persistanceProvider.saveValue(SYNC_TYPE, SYNC_TWO_WAY);
	}
	
	public boolean isOneWaySyncTypeSet() {
		return persistanceProvider.getValue(SYNC_TYPE).equals(SYNC_ONE_WAY);
	}
	
	public boolean isTwoWaySyncTypeSet() {
		return persistanceProvider.getValue(SYNC_TYPE).equals(SYNC_TWO_WAY);
	}
	
	public synchronized void setLocalSyncDirectory(String syncDirectory) {
		persistanceProvider.saveValue(SYNC_DIR, syncDirectory);
	}
	
	public synchronized String getLocalSyncDirectory() {
		return persistanceProvider.getValue(SYNC_DIR);
	}
}
